<?php
class Listing extends AppModel {

	var $name = 'Listing';
	var $displayField = 'title';

	var $actsAs = array(
		'MultipleValidatable'
	);
	
	/**
	 * ============================================== VALIDATIONS ==============================================
	 */
	/**
	 * Default validation ruleset
	 */
    var $validate = array();
    
	/**
	 * Custom validation rulesets
	 */
	var $validationSets = array(
        'submit' => array(
			'title' => array(
				'TitleRule1' => array(
	    			'rule' => array('minLength', '1'),
					'required' => true,
					'last' => true
				),
				'TitleRule2' => array(
	    			'rule' => array('custom', '/\S+/'),
					'last' => true
				)
			),
			'description' => array(
				'DescriptionRule1' => array(
	    			'rule' => array('minLength', '1'),
					'required' => true,
					'last' => true
				),
				'DescriptionRule2' => array(
	    			'rule' => array('custom', '/\S+/'),
					'last' => true
				),
				'DescriptionRule3' => array(
	    			'rule' => array('minLength', '10'),
					'last' => true
				)
			),
			'location_id' => array(
				'LocationRule1' => array(
					'rule' => array('minLength', '1'),
					'required' => true,
					'last' => true
				)
			),
			'category_id' => array(
				'CategoryRule1' => array(
					'rule' => array('minLength', '1'),
					'required' => true,
					'last' => true
				)
			)
    	),
		'admin_edit' => array(
			'id' => array(
				'IdRule1' => array(
	    			'rule' => array('minLength', '1'),
					'required' => true,
					'last' => true
				),
				'IdRule2' => array(
	    			'rule' => 'numeric',
					'last' => true
				),
				'IdRule3' => array(
	    			'rule' => array('comparison', '>', 0),
					'last' => true
				),
				'IdRule4' => array(
	    			'rule' => array('checkIdFieldValue'),
					'last' => true
				)
			),
			'is_active' => array(
				'IsActiveRule1' => array(
					'rule' => array('minLength', '1'),
					'required' => true,
					'last' => true
				),
				'IsActiveRule2' => array(
					'rule' => 'numeric',
					'last' => true
				)
			),
			'title' => array(
				'TitleRule1' => array(
	    			'rule' => array('minLength', '1'),
					'required' => true,
					'last' => true
				),
				'TitleRule2' => array(
	    			'rule' => array('custom', '/\S+/'),
					'last' => true
				)
			),
			'description' => array(
				'DescriptionRule1' => array(
	    			'rule' => array('minLength', '1'),
					'required' => true,
					'last' => true
				),
				'DescriptionRule2' => array(
	    			'rule' => array('custom', '/\S+/'),
					'last' => true
				)
			)
    	)
    );
    
	//--------------------------- check metodi za 'rule' => array('checkMethodName') opciqta
    var $idFieldValue = null;
    function checkIdFieldValue() {
    	return ( $this->idFieldValue == $this->data[$this->name]['id'] );
	}
       
	//--------------------------/ check metodi za 'rule' => array('checkMethodName') opciqta
		
	/**
	 * =============================================/ VALIDATIONS ==============================================
	 */

	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
		'Location' => array(
			'className' => 'Location',
			'foreignKey' => 'location_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Category' => array(
			'className' => 'Category',
			'foreignKey' => 'category_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	var $hasAndBelongsToMany = array(
		'ListingTag' => array(
			'className' => 'ListingTag',
			'joinTable' => 'listing_tags_listings',
			'foreignKey' => 'listing_id',
			'associationForeignKey' => 'listing_tag_id',
			'unique' => true,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => ''
		)
	);

}
